home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Software Vault: The Gold Collection
/
Software Vault - The Gold Collection (American Databankers) (1993).ISO
/
cdr48
/
pasclern.zip
/
LINKLIST.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1993-04-01
|
2KB
|
54 lines
PROGRAM linked_list_example;
TYPE next_pointer = ^full_name;
full_name = RECORD
first_name : STRING[12];
initial : CHAR;
last_name : STRING[15];
next : next_pointer;
END;
VAR start_of_list : next_pointer;
place_in_list : next_pointer;
temp_place : next_pointer;
index : INTEGER;
BEGIN (* main program *)
(* generate the first name in the list *)
new(place_in_list);
start_of_list := place_in_list;
place_in_list^.first_name := 'John';
place_in_list^.initial := 'Q';
place_in_list^.last_name := 'Doe';
place_in_list^.next := NIL;
(* generate another name in the list *)
temp_place := place_in_list;
new(place_in_list);
temp_place^.next := place_in_list;
place_in_list^.first_name := 'Mary';
place_in_list^.initial := 'R';
place_in_list^.last_name := 'Johnson';
place_in_list^.next := NIL;
(* add 10 more names to complete the list *)
FOR index := 1 TO 10 DO
BEGIN
temp_place := place_in_list;
new(place_in_list);
temp_place^.next := place_in_list;
place_in_list^.first_name := 'William';
place_in_list^.initial := 'S';
place_in_list^.last_name := 'Jones';
place_in_list^.next := NIL;
END;
(* display the list on the video monitor *)
place_in_list := start_of_list;
REPEAT
WRITE(place_in_list^.first_name);
WRITE(' ',place_in_list^.initial);
WRITELN(' ',place_in_list^.last_name);
temp_place := place_in_list;
place_in_list := place_in_list^.next;
UNTIL temp_place^.next = NIL;
END. (* of main program *)